<template>
  <div class="search_model">
    <el-form ref="form" :model="form" label-width="80px">
      <template v-for="(item, index) in dataObj.searchList">
        <el-form-item :label="item.searchName" :key="index">
          <el-date-picker
            v-if="item.searchType == 'timeRange'"
            v-model="form[item.searchField]"
            type="daterange"
            range-separator="至"
            start-placeholder="开始日期"
            end-placeholder="结束日期"
          >
          </el-date-picker>
          <el-select
            v-if="item.searchType == 'select'"
            v-model="form[item.searchField]"
            placeholder="请选择"
          >
            <el-option
              v-for="item in optionsList[index]"
              :key="item.enCode"
              :label="item.fullName"
              :value="item.enCode"
            >
            </el-option>
          </el-select>
        </el-form-item>
      </template>
      <el-button style="margin-left: 20px" @click="searchBtn" type="primary"
        >查 询</el-button
      >
    </el-form>
  </div>
</template>

<script>
export default {
  props: {
    dataObj: {},
  },
  data() {
    return {
      form: {
        value: "",
        isFixedAssets: "",
      },
      optionsList: [],
      options: [],
      value: "",
      isFixedAssetsOptions: [],
    };
  },
  created() {
    console.log("this.dataObj", this.dataObj);
    this.dataObj.searchList.forEach((item, index) => {
      if (item.searchType == "select") {
        this.$store
          .dispatch("base/getDictionaryData", {
            encode: item.selectCode,
          })
          .then((res) => {
            this.optionsList.push(res);
            console.log(this["options" + index], "this.options-----");
            this.form[item.searchField] = res[0].enCode;
            this.$emit("getObj", this.form);
          });
      } else {
        this.optionsList.push([]);
      }
    });
  },
  methods: {
    searchBtn() {
      console.log(this.form, "00000");
      if (this.form.datetime) {
        this.form.datetime = [
          this.form.datetime[0].toISOString(),
          this.form.datetime[1].toISOString(),
        ];
      }

      this.$emit("getObj", this.form);
    },
  },
};
</script>

<style lang="scss" scoped>
.search_model {
  width: 100%;
  height: 100%;
  padding: 4px 15px;
  background-color: #fff;
  .el-form-item {
    display: inline-block;
  }
  .el-form {
    // display: inline-block;
  }
  .el-input {
    width: 200px;
    display: inline-block;
  }
}
</style>
